import Vue from "vue";
import store from "@/store/index.js";
export function backToIndex(res) { //回到首页
	if (res.info == 'backIndex') {
		uni.switchTab({
			url: "/pages/viewPort/index"
		})
	}
}
// 节流函数 调用 throttle(handle,1000)
export function throttle(fn, wait) {
	var timer = null;
	return function() {
		var context = this;
		var args = arguments;
		if (!timer) {
			timer = setTimeout(function() {
				fn.apply(context, args);
				timer = null;
			}, wait)
		}
	}
}
// 根据传入的告警等级，返回告警等级name
export function chooseAlarmLevel(val) {
	let name = "";
	switch (val) {
		case '0':
			name = "正常"
			break;
		case '1':
			name = "警告告警"
			break;
		case '2':
			name = "次要告警"
			break;
		case '3':
			name = "主要告警";
			break;
		case "4":
			name = "紧急告警";
			break;
		default:
			name = "-";
			break;
	}
	return name
}
// 工具函数，对 swiper进行分类
export function handleSwiperGroup(obj, arr, keys) {
	const obj_temp = JSON.parse(JSON.stringify(obj))
	if (arr.length == 0) return obj
	arr.forEach((item) => {
		obj_temp['0'].push(item)
		obj_temp[item.alarmLevel].push(item)
	});
	return obj_temp
}
// 告警tabs
export function alarmTabs() {
	const tabs = [{
			name: "全部",
			alarmLevel: "0",
			count: "0"
		},
		{
			name: "警告",
			alarmLevel: "1",
			count: "0"
		}, {
			name: "次要",
			alarmLevel: "2"
		}, {
			name: "主要",
			alarmLevel: "3"
		}, {
			name: "紧急",
			alarmLevel: "4"
		}
	]
	return tabs
}
// 校验js 
/**
 * 手机号码
 * @param {* s} number 
 */
export function isMobile(s) {
	return /^1[0-9]{10}$/.test(s)
}
//rpx 转换为px
export function rpxToPx(val,windowWidth) {
	const sysWidth = windowWidth || uni.getSystemInfoSync().windowWidth;
	// const sysWidth = uni.getSystemInfoSync().windowWidth
	let value = val * 1
	let returnVal = ((value / 750) * sysWidth).toFixed(2);
	return returnVal
}
// 根据类型返回图标class名字
export function switchDeviceType(val) {
	let className = "pdg";
	switch (val) {
		case "0":
			className = "wsd";
			break;
		case "10":
			className = "pdg";
			break;
		case "1":
			className = "yg";
			break;
			// 单项ups 22
		case "22":
			className = "ups-dx";
			break;
			// 三项ups 11
		case "11":
			className = "ups-sx";
			break;
		case "13":
			className = "sp";
			break;
		case "2":
			className = "mj";
			break;
		case "4":
			className = "ls";
			break;
			// 精密空调 
		case "5":
			className = "jmkt";
			break;
			// 普通空调
		case "6":
			className = "ptkt";
			break;
			// 红外报警主机 - 14
		case "14":
			className = "hw-bgzj"
			break;
			// 红外传感器 - 23
		case "23":
			className = "hw";
			break;
			// 蓄电池
		case "12":
			className = "xdc";
			break;
			// 直流开关电源 29
		case "29":
			className = "zlkgdy";
			break;
			// 普通新风机 -7 
		case "7":
			className = "xfj-pt";
			break;
			// 智能新风机 - 24
		case "24":
			className = "xfj-zn";
			break;
		default:
			className = "kong";
			break;
	}
	return className;
}
// 根据类名返回图片地址
export function classNameUrl(name){
	let url = "";
	const baseUrl = store.state.baseUrl;
	const baseImgUrl = store.state.baseUrl + "/kimp1000";
	switch (name){
		case "fx-pao-blue":
			url = baseImgUrl + "/icon/blue.png";
			break;
		case "fx-pao-yellow":
			url = baseImgUrl + "/icon/yellow.png";
			break;
		case "fx-pao-orange":
			url = baseImgUrl + "/icon/orange.png";
			break;
		case "fx-pao-red":
			url = baseImgUrl + "/icon/pao.png";
			break;
		// 配电柜 10
		case "pdg":
			url = baseImgUrl + "/icon/box.png";
			break;
		case "ups":
			url = baseImgUrl + "/icon/ups.png";
			break;
		// 单项ups 22
		case "ups-dx":
			url = baseImgUrl + "/icon/ups.png";
			break;
		// 三项ups 11
		case "ups-sx":
			url = baseImgUrl + "/icon/ups-sx.png";
			break;
		// 温湿度 0
		case "wsd":
			url = baseImgUrl + "/icon/wsd.png";
			break;
		// 漏水 4
		case "ls":
			url = baseImgUrl + "/icon/ls.png";
			break;
		// 精密空调 5
		case "jmkt":
			url = baseImgUrl + "/icon/jmkt.png";
			break;
		// 普通空调 6
		case "ptkt":
			url = baseImgUrl + "/icon/ptkt.png";
			break;
		// 烟感 1
		case "yg":
			url = baseImgUrl + "/icon/yg.png";
			break;
		// 视频
		case "sp":
			url = baseImgUrl + "/icon/sp.png";
			break;
		// 门禁
		case "mj":
			url = baseImgUrl + "/icon/mj.png";
			break;
		// 红外传感器 23
		case "hw":
			url = baseImgUrl + "/icon/hw.png";
			break;
		// 红外报警主机 14
		case "hw-bgzj":
			url = baseImgUrl + "/icon/hw-bgzj.png";
			break;
		// 蓄电池 电池组 - 12
		case "xdc":
			url = baseImgUrl + "/icon/dcz.png";
			break;
		// 直流开关电源 29
		case "zlkgdy":
			url = baseImgUrl + "/icon/zlkgdy.png";
			break;
		// 普通新风机 -7 
		case "xfj-pt":
			url = baseImgUrl + "/icon/xfj-pt.png";
			break;
		// 智能新风机 - 24
		case "xfj-zn":
			url = baseImgUrl + "/icon/xfj-zn.png";
			break;
		// 照明控制器 - 8
		case "zmkzq":
			url = baseImgUrl + "/icon/zmkzq.png";
			break;
		// 消防主机
		default:
			url = baseImgUrl + "/icon/xfzj.png";
			break;
	}
	return url;
}